package cn.hexcloud.dga.governance.service.impl;

import cn.hexcloud.dga.governance.bean.GovernanceAssessDetail;
import cn.hexcloud.dga.governance.bean.GovernanceAssessGlobal;
import cn.hexcloud.dga.governance.bean.GovernanceAssessTable;
import cn.hexcloud.dga.governance.bean.GovernanceAssessTecOwner;
import cn.hexcloud.dga.governance.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jiangdan7
 */
@Service
public class MainAssessServiceImpl implements MainAssessService {
    @Autowired
    GovernanceAssessDetailService governanceAssessDetailService;

    @Autowired
    GovernanceAssessGlobalService governanceAssessGlobalService;

    @Autowired
    GovernanceAssessTableService governanceAssessTableService;

    @Autowired
    GovernanceAssessTecOwnerService governanceAssessTecOwnerService;

    @Override
    public void mainAssess(String assessDate) {
        //1 清理当日考评情况
        clearAssess(assessDate);
        // 2 考评指标明细生成
        governanceAssessDetailService.assessAllTableMetrics(assessDate);
        // 3  统计各表治理考评情况
        governanceAssessTableService.calcGovernanceAssessTable(assessDate);
        //4  统计计算负责人治理考评情况
        governanceAssessTecOwnerService.calcGovernanceAssess(assessDate);
        //5  统计全局治理考评情况
        governanceAssessGlobalService.calcGovernanceAssess (assessDate);
    }

    private void clearAssess(String assessDate) {
        governanceAssessDetailService.remove(new QueryWrapper<GovernanceAssessDetail>().eq("assess_date",assessDate));
        governanceAssessTableService.remove(new QueryWrapper<GovernanceAssessTable>().eq("assess_date",assessDate));
        governanceAssessTecOwnerService.remove(new QueryWrapper<GovernanceAssessTecOwner>().eq("assess_date",assessDate));
        governanceAssessGlobalService.remove(new QueryWrapper<GovernanceAssessGlobal>().eq("assess_date",assessDate));
    }
}
